#!/usr/bin/env python
# -*- coding: utf-8 -*-
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

from django.conf.urls.defaults import patterns, include, url
from sd import settings

classList = '(?P<class>(User|Article){1})'
suffixList = '.(?P<suffix>(do|html){1})'
actionList = '(?P<action>(add|edit|delete|list|listAll|detail|addCmt|delCmt|addParam|delParam|editParam|param|reply))?'
imgactionList = '(?P<action>(delete|list|upload|ueditor|mkdir|rmdir|imgs))?'
picsactionList = '(?P<action>(picsList|picsAdd|picsEdit|picsDelete|picsDetail))?'
prdactionList = '(?P<action>(add|edit|delete|list|listAll|detail|addParam|delParam|editParam|addCmt|delCmt))?'
imgList = '(?P<dir>(upload|images){1})'
commonList = '(?P<action>(contact))?'
pageList = '(?P<page>(contact){1})'

urlpatterns = patterns('sd.cms.views',
    url(r'^$', 'mainView.default'),
    url(r'^default.html$', 'mainView.default'),
    
    url(r'^'+commonList+suffixList+'$', 'commonView.action'),
    
    #用户模块
    url(r'^(?P<action>(login|logout){1})'+suffixList+'$', 'userView.action'),
    url(r'^'+actionList+'[!|-]?User[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'userView.action'),
    
    #文章模块
    url(r'^'+actionList+'[!|-]?Article[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'articleView.action'),
    url(r'^article[-]?(?P<id>\d*)[/]?(?P<name>[\w\-]*).html$', 'articleView.action'),
    
    #产品模块
    url(r'^'+prdactionList+'[!|-]?Product[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'productView.action'),
    url(r'^product[-]?(?P<id>\d*)[/]?(?P<name>[\w\-]*).html$', 'productView.action'),
    
    #图片模块
    url(r'^'+imgactionList+'Image/'+imgList+'(?P<path>[^.]*)'+suffixList+'$', 'imageView.action'),
    url(r'^'+picsactionList+'Image[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'imageView.action'),
    
    #留言簿模块
    url(r'^'+actionList+'[!|-]?GBook[-]?(?P<id>\d*)'+suffixList+'$', 'gbookView.action'),
    url(r'^guestbook.(?P<suffix>html{1})$', 'gbookView.action', {'action': 'list'}),
    
    #管理
    url(r'^admin[/]?$', 'admin.mainView.default'),
    url(r'^admin/innerDefault.html$', 'admin.mainView.innerDefault'),
    url(r'^admin/(?P<action>(flushmc))[!]Main?.do$', 'admin.mainView.action'),
    #目录
    url(r'^admin/'+actionList+'[!]?Column[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'admin.columnView.action'),
    url(r'^admin/'+actionList+'[!]?Catalog[-]?(?P<id>\d*)[/]?(?P<field>\w*)'+suffixList+'$', 'admin.catalogView.action'),
    #参数
    url(r'^admin/'+actionList+'[!]?Param[-]?(?P<id>\d*)[/]?(?P<kind>\d*)'+suffixList+'$', 'admin.paramView.action'),
    url(r'^admin/'+actionList+'[!]?Global[-]?(?P<id>\d*)[/]?(?P<kind>\d*)'+suffixList+'$', 'admin.globalView.action'),
    
    #url(r'^admin/Global'+suffixList+'$', 'admin.globalView.action'),

    #通用
    url(r'^valid(?P<view>\w*).do$', 'validView.action'),
    url(r'^safecode.gif$', 'include.safecode'),
    #default
    url(r'^pageList.html$', 'include.pages.view'),
    #url(r'^static/(?P<path>.*)$','django.views.static.serve', {'document_root':settings.STATIC_ROOT}),
)
#如果调试模式django会自动处理静态文件，如果是费调试模式需要在nginx中配置静态文件
if settings.DEBUG:
    urlpatterns += patterns('', url(r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),
                            url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATIC_ROOT}),)

handler404 = 'sd.cms.views.include.error.view404'
handler500 = 'sd.cms.views.include.error.view500'
